#ifndef __LOCK__
#define __LOCK__

#include <atomic>
#include <unordered_map>
#include "IUtility.h"
#include "ISysResources.h"



class CThreadLock : public virtual ILock, public virtual IProductInstance
{
INIT_CLASS_PRODUCT( CThreadLock )
public:
	bool const Init(const void * pvdPara, char * pszMsgTxt, int iMsgTxtSize);
	const void UnInit();
	const bool Lock(long long llLockTime = INFINITE);
	const void Unlock();

private:
	atomic_flag m_atoLock;
	CRITICAL_SECTION m_stSection;
};

class CProcessLock : public virtual ILock, public virtual IProductInstance
{
INIT_CLASS_PRODUCT( CProcessLock )
public:
	bool const Init(const void * pvdPara, char * pszMsgTxt, int iMsgTxtSize);
	const void UnInit();
	const bool Lock(long long llLockTime = INFINITE);
	const void Unlock();
private:
	enum { UNLOCK = 0, LOCK = 1 };
	HANDLE m_hMutx;
	volatile long long * m_llLock;
};

class CLockSet: public virtual ILockSet, public virtual IProductInstance
{
INIT_CLASS_PRODUCT( CLockSet )
public:
	bool const Init(const void * pvdPara, char * pszMsgTxt, int iMsgTxtSize);
	const bool Lock(const char * pszLockName, CLockType enLockType = emThreadLock);//long long llLockTime = 0xFFFFFFFF
	const bool UnLock(const char * pszLockName);
	ILock * GetLock(const char * pszLockName, CLockType enLockType = emThreadLock);

private:
	shared_ptr< ILock > m_ptrLock;
};

#endif//__LOCK__